package com.gxa.controller.system;

import com.gxa.annotation.Perm;
import com.gxa.mapper.system.UserRoleMapper;
import com.gxa.pojo.entity.system.User;
import com.gxa.pojo.entity.system.UserRole;
import com.gxa.service.system.UserRoleService;
import com.gxa.service.system.UserService;
import com.gxa.utils.MessageCode;
import com.gxa.utils.QueryResult;
import com.gxa.utils.Result;
import com.gxa.utils.ResultUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author lch
 * @Date 2024/2/22 16:04
 * @Description
 **/
@RestController
public class UserRoleController {

    @Resource
    private UserRoleService userRoleService;

    /**
     * 为用户添加角色
     * @param userRoleList
     */
    @Perm("user_role:add")
    @PostMapping("/user_role/add")
    public void addUserRole(@RequestBody List<UserRole> userRoleList) {
        userRoleService.addUserRole(userRoleList);
        System.out.println(userRoleList);
    }

    /**
     * 查询用户拥有的角色
     * @param userRole
     * @return
     */
    @GetMapping("/user_role/query")
    public Result queryUser(UserRole userRole) {
        QueryResult result = userRoleService.queryUserRole(userRole);
        return ResultUtils.buildSuccess(result.getData(), result.getCount());
    }
}
